package com.BigDecimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalDemo {
    public static void main(String[] args) {
       double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        //   请编程计算它们的总值及平均值(四舍五入保留小数点后2位)
       double sum=0.0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        System.out.println("他的总值为"+sum);
        BigDecimal bigDecimal = BigDecimal.valueOf(sum);
        //四舍五入保留2位小数
        BigDecimal result = bigDecimal.divide(BigDecimal.valueOf(arr.length), 2, RoundingMode.HALF_UP);
        System.out.println(result);
    }

}
